package cn.gmph.core.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @desc  
 * @author  
 * @date 2017年6月23日 下午4:04:24
 */
public class CodeUtil {

    public static String generateMerchantCode(String prefix) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        int month = calendar.get(Calendar.MONTH) + 1;
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        int value = (int) (Math.random() * (999999999 - 100000000) + 100000000);
        StringBuilder sb = new StringBuilder();
        sb.append(StringUtils.leftPad(String.valueOf(month), 2, '0')).append(StringUtils.leftPad(String.valueOf(day), 2, '0')).append(StringUtils.leftPad(String.valueOf(hour), 2, '0')).append(value);

        return sb.toString();
    }

    public static String generateOrderCode(String prefix) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        int month = calendar.get(Calendar.MONTH) + 1;
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        int minute = calendar.get(Calendar.MINUTE);
        int value = (int) (Math.random() * (99999999 - 10000000) + 10000000);
        StringBuilder sb = new StringBuilder();
        sb.append(prefix).append(StringUtils.leftPad(String.valueOf(month), 2, '0')).append(StringUtils.leftPad(String.valueOf(day), 2, '0')).append(StringUtils.leftPad(String.valueOf(hour), 2, '0'))
            .append(StringUtils.leftPad(String.valueOf(minute), 2, '0')).append(value);

        return sb.toString();
    }

    public static String generateorderReqNo(String prefix) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        long milles = System.currentTimeMillis();
        int value = (int) (Math.random() * (999999 - 100000) + 100000);
        StringBuilder sb = new StringBuilder();
        sb.append(prefix).append(milles).append(value);

        return sb.toString();
    }

    public static String generateBatchCode(String prefix) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        return prefix + sdf.format(new Date());
    }

    public static void main(String[] args) {
        System.out.println(generateMerchantCode("F"));
    }
}
